#pragma once
#ifndef _D3D_PARTICLES_
#define _D3D_PARTICLES_

#include "../common/def.h"
#include "d3d_texture.h"
#include "../math/matrix.h"
#include "d3d_util.h"
class CD3D9Device; 

struct EE_EXPORT D3DParticleSystem : public D3DRenderable
{
private:
	bool QueryEmit(float dt); 
protected:
	//todo: needed?
	friend struct D3DParticleShader; 
	
	Matrix4f mTransform; 
	Particle* mParticles; 
	void (*mpSpawnFunc) (D3DParticleSystem*,Particle*); 
	unsigned int m_Count; 
	float m_EmitTimer; 
	float m_Frequency; 
	float m_EmitCount; 

public:
	string GetType() const; 
	D3DParticleSystem(CD3D9Device* pRenderDevice); 
	HRESULT Reload(); 
	HRESULT Release(); 	
	
	virtual ~D3DParticleSystem(); 

	void SetTransform(const Matrix4f &transform) { mTransform = transform; }
	Matrix4f GetTransform() { return mTransform; }
	void setEmitFrequency(const float frequency); 
	void setEmitCount(const unsigned int count); 
	void setSpawnFunction(void (*pFunc) (D3DParticleSystem*, Particle*)); 

	void setCount(const unsigned int count); 
	void Draw(); 
	void Update(const float dt); 
	void ResetParticles(); 
	void setRenderFlags(const int flags); 

	void setTexture(Texture* pTexture, const unsigned int unit); 

	
	unsigned int getVertexCount() const;
	void* getVertices();
	Texture* getTexture(const unsigned int idx);
	HRESULT PreRender();
	void Render(const unsigned int vbOffset);
	HRESULT PostRender();
}; 
#endif